﻿using DirectUI.Mobile.UI;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DirectUI.Mobile.UI.Controls;
using DirectUI.Mobile.UI.Drawing.GdiPlus;
using System.Drawing;
namespace DirectUIUnitTest
{
  public   class Test:DirectUI.Mobile.UI.INotifyPropertyChange{
      private string _value = "what";
      public string TestValue
      {
          get
          {
              return _value;
              
          }
          set
          {
              _value = value;
              if (PropertyChanged != null)
              {
                  PropertyChangingEventArgs e = new PropertyChangingEventArgs("TestValue");
                  PropertyChanged(this, e);
              }
          }
      }
      private int _testInt;
      public int TestInt
      {
          get
          {
              return _testInt;
          }
          set
          {
              _testInt = value;
              if (PropertyChanged != null)
              {
                  PropertyChangingEventArgs e = new PropertyChangingEventArgs("TestInt");
                  PropertyChanged(this, e);
              }
          }
      }
      public event EventHandler<PropertyChangingEventArgs> PropertyChanged;
      private string[] _testArray = new string[5];
      public string[] TestArray
      {
          get
          {
              return _testArray;
          }
          set
          {
              _testArray = value;
          }
      }
    }
    
    /// <summary>
    ///This is a test class for DataBinderTest and is intended
    ///to contain all DataBinderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DataBinderTest
    {




        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion



        /// <summary>
        ///A test for GetPropertyValue
        ///</summary>
        [TestMethod()]
        public void GetPropertyValueTest()
        {
            DirectUI.Mobile.UI.Controls.DirectUILabel  container = new DirectUI.Mobile.UI.Controls.DirectUILabel("hello", 0, 0, 100, 100);

            string propName = "Text";
            string format = string.Empty; // TODO: Initialize to an appropriate value
            string expected = "hello";
            string actual;
            actual = DataBinder.GetPropertyValue(container, propName, format);
            Assert.AreEqual(expected, actual);
            expected = "world";
 DataBinder.SetPropertyValue(container, propName, expected);
 actual = DataBinder.GetPropertyValue(container, propName, format);
            Assert.AreEqual(expected, actual);

        }
        [TestMethod()]
        public void BindToControlTest1()
        {
            DirectUI.Mobile.UI.Controls.DirectUILabel container = new DirectUI.Mobile.UI.Controls.DirectUILabel("hello", 0, 0, 100, 100);

            Test test = new Test();
            test.TestValue = "hello";
            DataBinding bd = new DataBinding();
            bd.Path = new PropertyPath("TestValue");
            bd.DataSource = test;
            container.SetBinding("Text", bd);
            Assert.AreEqual("hello", container.Text);
            test.TestValue = "world";
            Assert.AreEqual("world", container.Text);
            DirectUITextBox tb = new DirectUITextBox();
            tb.SetBinding("Text", bd);
            test.TestValue = "what";
            Assert.AreEqual(tb.Text, container.Text);
            Assert.AreEqual("what", container.Text);

        }
        [TestMethod()]
        public void BindToControlTest2()
        {
            DirectUI.Mobile.UI.Controls.DirectUILabel container = new DirectUI.Mobile.UI.Controls.DirectUILabel("hello", 0, 0, 100, 100);

            Test test = new Test();
            test.TestValue = "hello";
            test.TestInt = 10;
            DataBinding bd = new DataBinding();
            bd.Path = new PropertyPath("TestInt");
            bd.DataSource = test;
            container.SetBinding("Text", bd);
            Assert.AreEqual("10", container.Text);
            test.TestInt = 5;
            Assert.AreEqual("5", container.Text);
            DirectUITextBox tb = new DirectUITextBox();
            tb.SetBinding("Text", bd);
            test.TestInt = 10;
            Assert.AreEqual(tb.Text, container.Text);
            Assert.AreEqual("10", container.Text);


        }
        [TestMethod()]
        public void BindToControlTest3()
        {
            DirectUI.Mobile.UI.Controls.DirectUILabel container = new DirectUI.Mobile.UI.Controls.DirectUILabel("hello", 0, 0, 100, 100);

            Test test = new Test();
            test.TestArray[0] = "hello";
            DataBinding bind = new DataBinding();
            bind.DataSource = test;
            bind.Mode = BindingMode.TwoWay;
            bind.Path = new PropertyPath("TestArray[0]");
            container.SetBinding("Text", bind);
            Assert.AreEqual(test.TestArray[0], container.Text);
            container.Text = "world";
            Assert.AreEqual(test.TestArray[0], container.Text);


        }
        [TestMethod()]
        public void FromStringTest()
        {
            string sColor = "red";
            Color expected = Color.Red;
            Color actual;
            actual = ColorConverter.FromString(sColor);
            Assert.AreEqual(expected, actual);
        }
    }
}
